//
//  WmcMediaTeamShareAPI.swift
//  YPWatermarkCamera
//
//  Created by 周诗松 on 2022/9/16.
//

import Foundation
import RxSwift
import YPNetwork

struct WmcMediaTeamShareAPI {
    /// 分享相册成员资源
    /// - Parameters:
    ///   - albumId: 相册id
    ///   - busId: 业务id，albumType为0时是鱼泡用户id
    ///   - uid: uid
    ///   - albumType: 相册类型，0：个人
    /// - Returns: Observable<WmcMediaShareResourceModel>
    static func applyShareResource(albumId: Int, uid: Int, albumType: Int) -> Observable<WmcMediaShareInfoModel> {
        var params: [String: Any] = ["albumId": albumId, "uid": uid, "albumType": albumType]
        if let userId = WmcLoginManager.shared.yupaoAccountModel?.userId {
            params["busId"] = userId
        }
        return WmcMediaRequest.requestData(path: "/wmc/v1/share/albumMemberResource", parameters: params) { request in
            request.method = .post
        }.parseModelWithClass(WmcMediaShareInfoModel.self)
    }

    /// 获取分享相册成员资源
    /// - Parameters:
    ///   - currentPage: 页码
    ///   - pageSize: 展示条数
    ///   - code: code
    /// - Returns: Observable<WmcMediaShareResourceModel>
    static func fetchShareResource(currentPage: Int, pageSize: Int, code: String) -> Observable<WmcMediaShareResourceModel> {
        let params: [String: Any] = ["currentPage": currentPage, "pageSize": pageSize, "code": code]
        return WmcMediaRequest.requestData(path: "/wmc/v1/share/getAlbumMemberResource", parameters: params) { request in
            request.method = .post
        }.parseModelWithClass(WmcMediaShareResourceModel.self)
    }

    /// 微信分享团队邀请
    /// - DocumentUrl: http://yapi.3pvr.com/project/219/interface/api/3211
    /// - Parameter teamId: 团队id
    /// - Returns: Observable<WmcMediaShareInfoModel>
    static func inviteToTeamByWechat(teamId: Int? = nil) -> Observable<WmcMediaShareInfoModel> {
        var params: [String: Any] = [:]
        if let teamId = teamId {
            params = ["teamId": teamId]
        }
        return WmcMediaRequest.requestData(path: "/wmc/v1/share/inviteTeamByWechat", parameters: params) { request in
            request.method = .post
        }.parseModelWithClass(WmcMediaShareInfoModel.self)
    }

    /// 获取微信分享连接
    /// - Returns: Observable<WmcMediaShareInfoModel>
    static func fetchInviteLink() -> Observable<WmcMediaShareInfoModel> {
        return WmcMediaRequest.requestData(path: "/wmc/v1/share/getWechatInviteLink") { request in
            request.method = .post
        }.parseModelWithClass(WmcMediaShareInfoModel.self)
    }

    /// 获取微信分享连接
    /// - Returns: Observable<WmcMediaShareInfoModel>
    static func fetchshareWechatGetShareTeamInfo(code: String) -> Observable<WmcMediaShareTeamModel> { 
        var params: [String: Any] = [:]
        params = ["code": code]
        return WmcMediaRequest.requestData(path: "/wmc/v1/share/wechatGetShareTeamInfo", parameters: params) { request in
            request.method = .post
        }.parseModelWithClass(WmcMediaShareTeamModel.self)
    }
}
